package org.example.controller;

import lombok.extern.slf4j.Slf4j;
import org.example.service.ProductFeignClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.loadbalancer.LoadBalancerClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

/**
 * @description: TODO
 * @author wangdpng
 * @date 2023/12/6 13:11
 */
@RestController
@Slf4j
//@RequestMapping(value = "/api/v2")
public class ConsumerController {
    @Autowired
    private LoadBalancerClient loadBalancerClient;
    @Autowired
    private ProductFeignClient productFeignClient;
    @GetMapping(value = "/consumer")
    public String Consumer(){
        ServiceInstance product = loadBalancerClient.choose("zkProductApplication");
        RestTemplate restTemplate = new RestTemplate();
        return restTemplate.getForObject(product.getUri().toString() + "/api/product", String.class);
    }

    @GetMapping(value = "/consumer2")
    public String ConsumerByFeign(){
        log.info("enter feign client");
        return productFeignClient.product();
    }
}
